$(document).ready(function () {
    viewSec();
    clickMenu();
    toggleMenu();
    $('.wrprNavIntSM33').data('size','big');
    $(".wrpDesAboutIntSM33").html("<span>We bring ...</span><span>all day delicious</span><span>various dishes for superb breakfast and dessert</span><span>pleasant taste even during meeting</span><span>enjoyment of your own cooking at home</span><span>party with friends in your style</span><span>... all we made it easy ...</span><span>... and deliver to you</span><span>anytime anywhere</span>")
    $(".ftIntSM33").html("<span>2014 © s i m p l e m e a l 3 3</span>")

    $(".bnnIntSM33").royalSlider({
        loop: true,
        imageScaleMode: 'fit',
        autoScaleSlider: true,
        transitionType: 'fade',
        navigateByClick: true,
        sliderDrag: false,
        sliderTouch: false,
        startSlideId: 0,
        autoPlay: true,
        slidesSpacing: 0,
        transitionSpeed: 1000,
        autoPlay: {
            enabled: true,
            
            delay: 3000
        }
    });  
});
$(window).bind("resize", hideShowMenu);
$(window).scroll(function() {
    clearTimeout($.data(this, 'scrollTimer'));
    $.data(this, 'scrollTimer', setTimeout(function() {
        $( ".navIntSM33" ).removeClass('clicked');
        //console.log("Haven't scrolled in 250ms!");
    }, 250));
});
$(window).scroll(function(){
    if($(document).scrollTop() > 80){
        if($('.wrprNavIntSM33').data('size') == 'big'){
            $('.wrprNavIntSM33').data('size','small');
            $('.wrprNavIntSM33').addClass('h80');
            $('.navIntSM33').addClass('lh80');
            $('.wrpLogoIntSM33').addClass('pd20');
        }
    }else{
        if($('.wrprNavIntSM33').data('size') == 'small'){
            $('.wrprNavIntSM33').data('size','big');
            $('.wrprNavIntSM33').removeClass('h80');
            $('.navIntSM33').removeClass('lh80');
            $('.wrpLogoIntSM33').removeClass('pd20');
        }  
    }
    if(!$('.navIntSM33').hasClass('clicked')){
        if($('#home').isOnScreen()){
            $('.navIntSM33').removeClass('slctNavIntSM33');
            $('#homelink').addClass('slctNavIntSM33');
        }else{
            $('#homelink').removeClass('slctNavIntSM33');
        }
        if($('#product').isOnScreen()){
            $('.navIntSM33').removeClass('slctNavIntSM33');
            $('#productlink').addClass('slctNavIntSM33');
        }else{
            $('#productlink').removeClass('slctNavIntSM33');
        }
        if($('#goodtoknow').isOnScreen()){
            $('.navIntSM33').removeClass('slctNavIntSM33');
            $('#goodtoknowlink').addClass('slctNavIntSM33');
        }else{
            $('#goodtoknowlink').removeClass('slctNavIntSM33');
        }
        if($('#Recipe').isOnScreen()){
            $('.navIntSM33').removeClass('slctNavIntSM33');
            $('#Recipelink').addClass('slctNavIntSM33');
        }else{
            $('#Recipelink').removeClass('slctNavIntSM33');
        }
        
        
         if($('#facebook').isOnScreen()){
            $('.navIntSM33').removeClass('slctNavIntSM33');
            $('#facebooklink').addClass('slctNavIntSM33');
        }else{
            $('#facebooklink').removeClass('slctNavIntSM33');
        }
        
        
         if($('#reservation').isOnScreen()){
            $('.navIntSM33').removeClass('slctNavIntSM33');
            $('#reservationlink').addClass('slctNavIntSM33');
        }else{
            $('#reservationlink').removeClass('slctNavIntSM33');
        }
        
        
        if($('#about').isOnScreen()){
            $('.navIntSM33').removeClass('slctNavIntSM33');
            $('#aboutlink').addClass('slctNavIntSM33');
        }else{
            $('#aboutlink').removeClass('slctNavIntSM33');
        }
        if($('#find').isOnScreen()){
            $('.navIntSM33').removeClass('slctNavIntSM33');
            $('#findlink').addClass('slctNavIntSM33');
        }else{
            $('#findlink').removeClass('slctNavIntSM33');
        }
    }
});

function hideShowMenu() {
    if ($(window).width() > 1040) {
        $(".wrpInNavIntSM33").addClass("expandMenu").removeClass("toggle").show();
        $(".menuNavIntSM33").hide();
    } else {
        $(".wrpInNavIntSM33").addClass("toggle").removeClass("expandMenu").hide();
        $(".menuNavIntSM33").show();
    }
    if ($(window).width() > 500) {
        $(".wrpInNavPdIntSM33").addClass("expandMenu").removeClass("toggle").show();
        $(".menuNavPdIntSM33").hide();
    } else {
        $(".wrpInNavPdIntSM33").addClass("toggle").removeClass("expandMenu").hide();
        $(".menuNavPdIntSM33").show();
    }
}
function toggleMenu() {
    $(".menuNavIntSM33").click(function() {
        $(".wrpInNavIntSM33.toggle").toggle();
    });
    $(".menuNavPdIntSM33").click(function() {
        $(".wrpInNavPdIntSM33.toggle").toggle();
    });
    hideShowMenu();
    $(".navIntSM33").click(function() {
        $(".wrpInNavIntSM33.toggle").hide();
    });
    $(".navPdIntSM33").click(function() {
        $(".wrpInNavPdIntSM33.toggle").hide();
    });
}
function goToByScroll(id){
    id = id.replace("link", "")
    $('html,body').animate({
        scrollTop: $("#"+id).offset().top},
        'slow')
}
function clickMenu(){
    $(".wrpOutNavIntSM33 > ul > li").click(function(e) {
        e.preventDefault(); 
        goToByScroll($(this).attr("id"));           
    });
    $('.navIntSM33').click(function(){
        $('.navIntSM33').addClass('slctNavIntSM33 clicked').not(this).removeClass('slctNavIntSM33');
    });

    $('.navPdIntSM33').click(function() {
        $('.navPdIntSM33').addClass('slctNavPdIntSM33').not(this).removeClass('slctNavPdIntSM33');
    });
}
// function removeMenuClicked() {
//        $( window ).scroll(function() {
//           $( ".navIntSM33" ).removeClass('clicked');
//         });
// }
function viewSec(){
    $.fn.isOnScreen = function(){

        var win = $(window);
        
        var viewport = {
            top : win.scrollTop(),
            left : win.scrollLeft()
        };
        viewport.right = viewport.left + win.width();
        viewport.bottom = viewport.top + win.height() - win.height()/2;
        
        var bounds = this.offset();
        if(bounds)
        {
        bounds.right = bounds.left + this.outerWidth();
        bounds.bottom = bounds.top + this.outerHeight();
        
        return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom));
        }else
        {
        
        return 0;
        }
        
    };
}

function searchbytagid(tagid2,fid,link)
{
var tagid=new Array();
tagid[0]=tagid2;
var code='';
$.get(serviceinfo+'getproduct', { page:1,fid:fid,tagid:tagid }, function(data) {  

if(data.data.length)
{
         $.each(data.data, function(key, value) {
         
code += '<div class="wrpIntSM33">\n';
code += '<div class="tmbIntSM33">\n';
code += '<a href="'+baseinfo+'/post/'+value.productid+'">\n';
code += '<img alt="img" src="'+value.simg.newpath+'">\n';
code += '</a>\n';
code += '</div>\n';
code += '<div class="ttlPrcIntSM33 clearfix">\n';
code += '<div class="ttlIntSM33">\n';
code += '<span>'+value.title+'</span>\n';
code += '</div>\n';

if(value.show.price&&value.show.price!='0.00 ')
{
code += '<div class="prcIntSM33">\n';
code += '<span>'+value.show.price+'</span>\n';
code += '</div>\n';
}

code += '</div>\n';
code += '</div>';
         });
         
         
}
$('#'+link+' .wrpInIntSM33').html(code);

});


}